/*
 * Tiled Map Editor (Qt)
 * Copyright 2010 Tiled (Qt) developers (see AUTHORS file)
 *
 * This file is part of Tiled (Qt).
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef PIXMAPREF_H
#define PIXMAPREF_H

#include <QMetaType>
#include <QPixmap>

/**
 * A reference to part of a QPixmap. Used to avoid copying the tiles out of the
 * tileset individually.
 *
 * This class keeps the pixmap data alive, so it does not need to be kept
 * around explicitly.
 */
class PixmapRef
{
public:
    PixmapRef() {}

    PixmapRef(const QPixmap &pixmap, const QRect &rect)
        : mPixmap(pixmap)
        , mRect(rect)
    {}

    int width() const { return mRect.width(); }
    int height() const { return mRect.height(); }

    /**
     * Returns the referenced pixmap.
     */
    const QPixmap &pixmap() const { return mPixmap; }

    /**
     * Returns the source rectangle referenced in the pixmap.
     */
    const QRect &rect() const { return mRect; }

private:
    QPixmap mPixmap;
    QRect mRect;
};

Q_DECLARE_METATYPE(PixmapRef)

#endif // PIXMAPREF_H
